//
//  ViewController.m
//  高斯模糊Demo
//
//  Created by SKY on 15/11/22.
//  Copyright © 2015年 翊sky. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UILabel *lable1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 80, 100, 20)];
    [self.view addSubview:lable1];
    lable1.text = @"原图";
    //原图
    UIImageView *pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, self.view.frame.size.width - 20, 200)];
    [self.view addSubview:pictureView];
    pictureView.image = [UIImage imageNamed:@"bg.jpg"];
    
    
    UILabel *lable2 = [[UILabel alloc]initWithFrame:CGRectMake(20, 330, 320, 20)];
    [self.view addSubview:lable2];
    lable2.text = @"高斯模糊后(从视觉上来看，随模糊程度加深图片会变小)";
    
    //高斯模糊后图片
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *image = [CIImage imageWithCGImage:[UIImage imageNamed:@"bg.jpg"].CGImage];
    //如果是网络图片用 CIImage *image = [CIImage imageWithContentsOfURL:imageURL];
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setValue:image forKey:kCIInputImageKey];
    [filter setValue:@8.0 forKey: @"inputRadius"];
    CIImage *result = [filter valueForKey:kCIOutputImageKey];
    CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];
    UIImage * blurImage = [UIImage imageWithCGImage:outImage];
    
    UIImageView *blurView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 350, self.view.frame.size.width - 20, 200)];
    [self.view addSubview:blurView];
    blurView.image = blurImage;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
